import * as monaco from 'monaco-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';

// @ts-ignore
self.MonacoEnvironment = {
	getWorker(_: any, label: string) {
		if (label === 'json') {
			return new jsonWorker();
		}
		if (label === 'css' || label === 'scss' || label === 'less') {
			return new cssWorker();
		}
		if (label === 'html' || label === 'handlebars' || label === 'razor') {
			return new htmlWorker();
		}
		if (label === 'typescript' || label === 'javascript') {
			return new tsWorker();
		}
		return new editorWorker();
	}
};
monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true);



// <script>self["MonacoEnvironment"] = (function (paths) {
// 	return {
// 	  globalAPI: false,
// 	  getWorkerUrl : function (moduleId, label) {
// 		var result =  paths[label];
// 		if (/^((http:)|(https:)|(file:)|(\/\/))/.test(result)) {
// 		  var currentUrl = String(window.location);
// 		  var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);
// 		  if (result.substring(0, currentOrigin.length) !== currentOrigin) {
// 			var js = '/*' + label + '*/importScripts("' + result + '");';
// 			var blob = new Blob([js], { type: 'application/javascript' });
// 			return URL.createObjectURL(blob);
// 		  }
// 		}
// 		return result;
// 	  }
// 	};
//   })({
// "editorWorkerService": "/monacoeditorwork/editor.worker.bundle.js",
// "typescript": "/monacoeditorwork/ts.worker.bundle.js",
// "json": "/monacoeditorwork/json.worker.bundle.js",
// "html": "/monacoeditorwork/html.worker.bundle.js",
// "css": "/monacoeditorwork/css.worker.bundle.js",
// "javascript": "/monacoeditorwork/ts.worker.bundle.js",
// "less": "/monacoeditorwork/css.worker.bundle.js",
// "scss": "/monacoeditorwork/css.worker.bundle.js",
// "handlebars": "/monacoeditorwork/html.worker.bundle.js",
// "razor": "/monacoeditorwork/html.worker.bundle.js"
// });</script>